// 加一

package Leetcode;

class solution_066 {
    public static int[] plusOne(int[] digits) {
        int count = 0;
        int index = digits[digits.length - 1] + 1 + count;
        digits[digits.length - 1] = index % 10;
        count = index / 10;
        for (int i = digits.length - 2; i >= 0; i--) {
            index = digits[i] + count;
            digits[i] = index % 10;
            count = index / 10;
        }
        if (count != 0) {
            int[] result = new int[digits.length + 1];
            result[0] = count;
            for (int i = 0; i < digits.length; i++)
                result[i + 1] = digits[i];
            return result;
        }
        return digits;
    }

    public static void main(String[] args) {
        int[] in = new int[] { 9 };
        for (int i : plusOne(in))
            System.out.println(i);
    }
}

public class Solution066 {

}
